package com.wayneleo.launcher.core;

import java.util.logging.Logger;

/**
 * 主类
 *
 * @author wayne
 */
public class Launcher {
    private static final Logger LOG = Logger.getLogger(Launcher.class.getName());

    private Launcher() {
    }

    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        LOG.info("Launcher is running");
        initLauncher();
        ModuleLoader.initModules(args);
        ModuleLoader.destroyModules();
        LOG.info("Launcher is shutdown: " + (System.currentTimeMillis() - startTime));
    }

    private static void initLauncher() {
        String homeDir = System.getProperty(Const.HOME_DIR);
        if (null == homeDir || "".equals(homeDir)) {
            throw new InitLauncherException("System property \"LAUNCHER_HOME\" is not found!");
        }
        String moduleConfFilename = System.getProperty(Const.MODULE_CONF_FILENAME);
        if (null == moduleConfFilename || "".equals(moduleConfFilename)) {
            throw new InitLauncherException("System property \"MODULE_CONF_FILE\" is not found!");
        }
        LauncherContext.init(homeDir, moduleConfFilename);
    }
}
